<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
<meta name="generator" content="litedown 0.7">
<title></title>
<style type="text/css">
body {
  font-family: sans-serif;
  max-width: 800px;
  margin: auto;
  padding: 1em;
  line-height: 1.5;
  print-color-adjust: exact;
  -webkit-print-color-adjust: exact;
}
body, .abstract, code, .footnotes, footer, #refs, .caption { font-size: .9em; }
li li { font-size: .95em; }
ul:has(li > input[type="checkbox"]) { list-style: none; padding-left: 1em; }
*, :before, :after { box-sizing: border-box; }
a { color: steelblue; }
pre, img { max-width: 100%; }
pre { white-space: pre-wrap; word-break: break-word; }
pre code { display: block; padding: 1em; overflow-x: auto; }
code { font-family: 'DejaVu Sans Mono', 'Droid Sans Mono', 'Lucida Console', Consolas, Monaco, monospace; }
:not(pre, th) > code, code[class], div > .caption { background: #f8f8f8; }
pre > code:is(:not([class]), .language-plain, .language-none, .plain), .box, .figure, .table { background: inherit; border: 1px solid #eee; }
pre > code {
  &.message { border-color: #9eeaf9; }
  &.warning { background: #fff3cd; border-color: #fff3cd; }
  &.error { background: #f8d7da; border-color: #f8d7da; }
}
.fenced-chunk { border-left: 1px solid #666; }
.code-fence {
  opacity: .4;
  border: 1px dashed #666;
  border-left: 2px solid;
  &:hover { opacity: inherit; }
}
.box, .figure, .table, table { margin: 1em auto; }
div > .caption { padding: 1px 1em; }
.figure { p:has(img, svg), pre:has(svg) { text-align: center; } }
.flex-col { display: flex; justify-content: space-between; }
table {
  &:only-child:not(.table > *) { margin: auto; }
  th, td { padding: 5px; font-variant-numeric: tabular-nums; }
  thead, tfoot, tr:nth-child(even) { background: whitesmoke; }
  thead th { border-bottom: 1px solid #ddd; }
  &:not(.datatable-table) {
    border-top: 1px solid #666;
    border-bottom: 1px solid #666;
  }
}
blockquote {
  color: #666;
  margin: 0;
  padding: 1px 1em;
  border-left: .5em solid #eee;
}
hr, .footnotes::before { border: 1px dashed #ddd; }
.frontmatter { text-align: center; }
#TOC {
  a { text-decoration: none; }
  ul { list-style: none; padding-left: 1em; }
  & > ul { padding: 0; }
  ul ul { border-left: 1px solid lightsteelblue; }
}
.body h2 { border-bottom: 1px solid #666; }
.body .appendix, .appendix ~ h2 { border-bottom-style: dashed; }
.main-number::after { content: "."; }
span[class^="ref-number-"] { font-weight: bold; }
.ref-number-fig::after, .ref-number-tab::after { content: ":"; }
.cross-ref-chp::before { content: "Chapter "; }
.cross-ref-sec::before { content: "Section "; }
.cross-ref-fig::before, .ref-number-fig::before { content: "Figure "; }
.cross-ref-tab::before, .ref-number-tab::before { content: "Table "; }
.cross-ref-eqn::before, .MathJax_ref:has(mjx-mtext > mjx-c + mjx-c)::before { content: "Equation "; }
.abstract, #refs {
  &::before { display: block; margin: 1em auto; font-weight: bold; }
}
.abstract::before { content: "Abstract"; text-align: center; }
#refs::before { content: "Bibliography"; font-size: 1.5em; }
.ref-paren-open::before { content: "("; }
.ref-paren-close::after { content: ")"; }
.ref-semicolon::after { content: "; "; }
.ref-and::after { content: " and "; }
.ref-et-al::after { content: " et al."; font-style: italic; }
.footnote-ref a {
  &::before { content: "["; }
  &::after { content: "]"; }
}
section.footnotes {
  margin-top: 2em;
  &::before { content: ""; display: block; max-width: 20em; }
}
.fade {
  background: repeating-linear-gradient(135deg, white, white 30px, #ddd 32px, #ddd 32px);
  opacity: 0.6;
}

@media print {
  body { max-width: 100%; }
  tr, img { break-inside: avoid; }
}
@media only screen and (min-width: 992px) {
  body:not(.pagesjs) pre:has(.line-numbers):not(:hover) { white-space: pre; }
}
</style>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@xiee/utils@1.14.14/css/prism-xcode.min.css">
<script src="https://cdn.jsdelivr.net/npm/prismjs@1.29.0/components/prism-core.min.js" defer></script>
<script src="https://cdn.jsdelivr.net/npm/prismjs@1.29.0/plugins/autoloader/prism-autoloader.min.js" defer></script>
</head>
<body>
<div class="frontmatter">
</div>
<div class="body">
<pre><code class="language-r">library(tidyverse)
</code></pre>
<pre><code>## Error in library(tidyverse): there is no package called 'tidyverse'
</code></pre>
<pre><code class="language-r">library(xgboost)
</code></pre>
<pre><code>## Error in library(xgboost): there is no package called 'xgboost'
</code></pre>
<pre><code class="language-r">ind&lt;-sample(2,nrow(diamonds),replace = T,prob = c(0.7,0.3))
</code></pre>
<pre><code>## Error in nrow(diamonds): object 'diamonds' not found
</code></pre>
<pre><code class="language-r">train.set&lt;-diamonds[ind==1,]
</code></pre>
<pre><code>## Error: object 'diamonds' not found
</code></pre>
<pre><code class="language-r">test.set&lt;-diamonds[ind==2,]
</code></pre>
<pre><code>## Error: object 'diamonds' not found
</code></pre>
<pre><code class="language-r">xgb.train&lt;-bind_cols(select_if(train.set,is.numeric),model.matrix(~cut-1,train.set) %&gt;% as.tibble(),model.matrix(~color-1,train.set) %&gt;% as.tibble(),model.matrix(~clarity-1,train.set) %&gt;% as.tibble())
</code></pre>
<pre><code>## Error in bind_cols(select_if(train.set, is.numeric), model.matrix(~cut - : could not find function &quot;bind_cols&quot;
</code></pre>
<pre><code class="language-r">xgboost.train&lt;-xgb.DMatrix(data = as.matrix(select(xgb.train,-price)),label=xgb.train$price)
</code></pre>
<pre><code>## Error in xgb.DMatrix(data = as.matrix(select(xgb.train, -price)), label = xgb.train$price): could not find function &quot;xgb.DMatrix&quot;
</code></pre>
<pre><code class="language-r">xgb.test&lt;-bind_cols(select_if(test.set,is.numeric),model.matrix(~cut-1,test.set) %&gt;% as.tibble(),model.matrix(~color-1,test.set) %&gt;% as.tibble(),model.matrix(~clarity-1,test.set) %&gt;% as.tibble())
</code></pre>
<pre><code>## Error in bind_cols(select_if(test.set, is.numeric), model.matrix(~cut - : could not find function &quot;bind_cols&quot;
</code></pre>
<pre><code class="language-r">xgboost.test&lt;-xgb.DMatrix(data = select(xgb.test,-price) %&gt;% as.matrix(),label=xgb.test$price)
</code></pre>
<pre><code>## Error in xgb.DMatrix(data = select(xgb.test, -price) %&gt;% as.matrix(), : could not find function &quot;xgb.DMatrix&quot;
</code></pre>
<pre><code class="language-r">param&lt;-list(eval_metric='rmse',gamma=1,max_depth=6,nthread = 3)
xg.model&lt;-xgb.train(data = xgboost.train,params = param,watchlist = list(test=xgboost.test),nrounds = 500,early_stopping_rounds = 60,
                      print_every_n = 30)
</code></pre>
<pre><code>## Error in xgb.train(data = xgboost.train, params = param, watchlist = list(test = xgboost.test), : could not find function &quot;xgb.train&quot;
</code></pre>
<pre><code class="language-r">xg.predict&lt;-predict(xg.model,xgboost.test)
</code></pre>
<pre><code>## Error in predict(xg.model, xgboost.test): object 'xg.model' not found
</code></pre>
<pre><code class="language-r">mse.xgb&lt;-sqrt(mean((test.set$price-xg.predict)^2))
</code></pre>
<pre><code>## Error in mean((test.set$price - xg.predict)^2): object 'test.set' not found
</code></pre>
<pre><code class="language-r">plot((test.set$price-xg.predict))
</code></pre>
<pre><code>## Error in plot((test.set$price - xg.predict)): object 'test.set' not found
</code></pre>
</div>
</body>
</html>
